Vue.component("upload-images", {
  template: `<el-upload class="upload-demo" :show-file-list="false" accept="image/*" drag :on-change="upload" :auto-upload="false" action="" multiple>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">
            只能上传jpg/png文件
            <el-slider :min="1" v-model="quality" :format-tooltip="formatTooltip"></el-slider>
            <div v-show="quality < 100">当前图片压缩至{{quality}}%</div>
        </div>
    </el-upload>
    `,
  props: ["data", "id"],
  data() {
    return {
      quality: 100,
    };
  },
  mounted() { },
  methods: {
    formatTooltip(val) {
      return "图片压缩比例：" + val + "%";
    },
    upload({ raw }) {
      const that = this;
      // console.log(raw);
      // console.log( raw.size / 1024 / 1024);
      new Compressor(raw, {
        quality: that.quality / 100,
        success(file) {
          const isJPGorPNG =
            file.type === "image/jpeg" || file.type === "image/png";
          const isLt500K = file.size / 1024 / 1024 < 10;
          if (!isJPGorPNG) {
            that.$message({
              message: "上传头像图片只能是 JPG/PNG 格式!",
              type: "warning",
            });
            return false;
          }
          if (!isLt500K) {
            that.$message({
              message: "上传图片大小不能超过 10MB! 可压缩后上传",
              type: "warning",
            });
            return false;
          }
          const formData = new FormData();
          formData.append("file", file, file.name);
          let oFileReader = new FileReader();
          oFileReader.readAsDataURL(file);
          oFileReader.onload = function (e) {
            $.ajax({
              headers: requestHeaders("JSON"),
              // url: `${BASE_URL2}/generalBusiness/generalSaveFilesAsImage`,
              url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
              type: "POST",
              data: JSON.stringify({
                Data: e.target.result,
                DataLength: file.size,
                FileName: file.name,
              }),
              complete: function (XMLHttpRequest) {
                requestPretreatment(XMLHttpRequest);
              },
              success: function (Result) {
                if (Result.Status == "success") {
                  that.$message.success("上传成功");
                  that.data.push({
                    Base64: e.target.result,
                    Picture_URL: Result.FileName,
                    Picture_Type: 0,
                    id: that.id,
                  });
                } else {
                  that.$message.error("上传失败");
                }
              },
              error: function () {
                that.$message.error("图片过大，可尝试压缩");
              },
              dataType: "json",
            });
          };
        },
      });
    },
  },
});
Vue.component("yl-upload1", {
  template: `<div>
    <div class="preview" style="width:100px;height:100px" v-if="Picture_URL">
        <el-image class="el-upload-list__item-thumbnail" style="width: 100px; height: 100px" :src="base64?Picture_URL:base + Picture_URL" fit="contain"></el-image>
        <span class="el-upload-list__item-actions" style="width:100px;height:100px">
            <span @click="handlePictureCardPreview(base64?Picture_URL:base + Picture_URL)"><i class="el-icon-zoom-in"></i></span>
            <span @click="handleRemove"><i class="el-icon-delete"></i></span>
        </span>
    </div>
    <el-upload id="group" :disabled="loading" v-else class="upload-demo" :show-file-list="false" :on-change="upload"
        list-type="picture-card" action="" accept="image/*" :auto-upload="false">
        <i slot="default" :class="loading?'el-icon-loading':'el-icon-plus'"></i>
        <div v-if="!unslider" class="el-upload__tip" slot="tip">
            <div v-show="quality < 100">当前图片压缩至{{quality}}%</div>
            <el-slider :min="1" style="width:148px" v-model="quality" :format-tooltip="formatTooltip"></el-slider>
        </div>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <el-image width="100%" fit="contain" :src="dialogImageUrl">
    </el-dialog></div>`,
  props: {
    value: {
      type: String,
      default: "",
    },
    base: {
      type: String,
      default: "",
    },
    base64: {
      type: Boolean,
      default: false,
    },
    unslider: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      Picture_URL: this.value,
      loading: false,
      dialogVisible: false,
      dialogImageUrl: "",
      quality: 100,
    };
  },
  watch: {
    value(newVal) {
      this.Picture_URL = newVal;
    },
    Picture_URL(newVal) {
      this.$emit("input", newVal);
    },
  },
  methods: {
    formatTooltip(val) {
      return "图片压缩比例：" + val + "%";
    },
    upload({ raw }) {
      const that = this;
      new Compressor(raw, {
        quality: that.quality / 100,
        success(file) {
          that.loading = true;
          const formData = new FormData();
          formData.append("file", file, file.name);
          let oFileReader = new FileReader();
          oFileReader.readAsDataURL(file);
          oFileReader.onload = function (e) {
            if (!that.base64) {
              $.ajax({
                headers: requestHeaders("JSON"),
                // url: `${BASE_URL2}/generalBusiness/generalSaveFilesAsImage`,
                url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
                type: "POST",
                data: JSON.stringify({
                  Data: e.target.result,
                  DataLength: file.size,
                  FileName: file.name,
                }),
                success: function (Result) {
                  if (Result.Status == "success") {
                    that.Picture_URL = Result.FileName;
                    that.$message.success("上传成功");
                  } else {
                    that.$message.error("上传失败");
                  }
                },
                complete: function (XMLHttpRequest) {
                  that.loading = false;
                  requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
              });
            } else {
              that.Picture_URL = e.target.result;
              that.loading = false;
            }
          };
        },
        error(err) {
          console.log(err.message);
        },
      });
    },
    handlePictureCardPreview(Val) {
      this.dialogVisible = true;
      this.dialogImageUrl = Val;
    },
    handleRemove() {
      this.Picture_URL = "";
    },
  },
});
new Vue({
  el: "#app",
  data() {
    return {
      Add: [],
      upLoadFilesList: new Array(new Array()),
      jcfileList: [],
      xfileList: [],
      zfileList: [],
      fileList: [],
      uploadFileList: [],
      dj: {},
      fh: {},
      dh: {},
      wk: {},
      business_article_specifications: [],
      category: [], //类别
      is_Article_Type: "", // 包装信息
      is_Unit_Price: "",
      is_JDCOM_Unit_Price: "",
      bzdw: [
        {
          value: "箱",
          label: "箱",
        },
        {
          value: "瓶",
          label: "瓶",
        },
        {
          value: "袋",
          label: "袋",
        },
      ],
      article_info: [
        {
          value: "预包装",
          label: "预包装",
        },
      ], //包装信息
      VarietyID: "",
      GradeID: "",
      iJSONArray_Variety: [],
      iJSONArray_VarietyGrade: [],
      form: {
        ClassifyJSON: "",
        Article_Name: "", //商品名称

        Brand_SerialNumber: "", //商品品牌
        Category_SerialNumber: "", //商品类别
      },

      rules: {
        Article_Name: [
          { required: true, message: "请输入商品名称", trigger: "blur" },
        ],
        Brand_SerialNumber: [
          { required: true, message: "请选择商品品牌", trigger: "change" },
        ],
        // Unit_Price: [{ required: true, message: '请输入商品吊牌价', trigger: 'change' }],
        Specifications_Name: [
          { required: true, message: "请输入规格名称", trigger: "blur" },
        ],
        // SKU_Quantity: [{ required: true, message: '请输入SKU数量', trigger: 'blur' }]
      },
      item: [],
      Main_Image: [],
      Detail_Image: [],
      brand: [], //品牌
      unit: [], //单位
      supplier: [], //供应商
      activity: [], //活动
      classify: [],
      // business_article_classify: [],
      defaultProps: {
        children: "Children",
        label: "Classify_Name",
        value: "Classify_SerialNumber",
        multiple: true,
      },
      loading: false,
      isMainSort: false, //主图排序
      isDetailSort: false, //详情图排序
      MainSortable: null, //主图拖拽
      DetailSortable: null, //详情图拖拽
      activeName: 0, //图片
      business_article_group: [],
    };
  },
  mounted() {
    this.spxx();
    this.spgg();
    this.getVarietyList();
    this.getbrandList();
    this.getcategoryList();
    this.cjd();
    this.sortable(
      this,
      "#Main_Image",
      ".preview",
      this.Main_Image,
      "MainSortable"
    );
    this.sortable(
      this,
      "#Detail_Image",
      ".preview",
      this.Detail_Image,
      "DetailSortable"
    );
    this.business_article_group.push({
      Specification_Group_Name: "规格",
      Picture_URL: "",
      Children: {
        business_article_group_detail: [
          {
            id: createUniqueString(),
            Specification_Group_Detail_Name: "",
          },
        ],
      },
    });
    // 确保 business_article_specifications 至少有一个默认项
    if (this.business_article_specifications.length === 0) {
      let Article_SerialNumber = sessionStorage.getItem("Article_SerialNumber");
      this.business_article_specifications.push({
        Specifications_Name: "",
        Unit_Price: "", // 吊牌价
        SKU_Quantity: "", // SKU数量
        Size: "",
        ADD: "ADD",
        Article_SerialNumber: Article_SerialNumber,
      });
    }
  },
  watch: {
    isMainSort(val) {
      this.MainSortable.option("disabled", !val);
    },
    isDetailSort(val) {
      this.DetailSortable.option("disabled", !val);
    },
    "form.Unit_Price": function (val) {
      if (this.form.Unify_Unit_Price == "1") {
        this.form.Children.business_article_specifications.forEach((item) => {
          item.Unit_Price = val;
        });
      }
    },
    "form.Unify_Unit_Price": function (val) {
      if (val == "1") {
        this.form.Children.business_article_specifications.forEach((item) => {
          item.Unit_Price = this.form.Unit_Price;
        });
      }
    },
  },
  computed: {
    business_supplier_article() {
      let business_supplier_article = [];
      this.form.Children.business_article_specifications.forEach((item) => {
        item.Other.filter((i) => i.Supplier_SerialNumber).forEach((ite) => {
          business_supplier_article.push({
            Supplier_Article_SerialNumber: "",
            Article_Name: this.form.Article_Name,
            Specifications_Name: item.Specifications_Name,
            Brand_SerialNumber: this.form.Brand_SerialNumber,
            Supplier_SerialNumber: ite.Supplier_SerialNumber,
            Article_SerialNumber: "",
            Article_Specifications_SerialNumber: "",
            Shelf: "1",
            Sales_Unit_Price: ite.Sales_Unit_Price,
            Purchase_Unit_Price: ite.Purchase_Unit_Price,
            Quantity: ite.Quantity,
            Pionts: ite.Pionts,
            Deduction_Type: ite.Deduction_Type,
            Deduction_Limit: ite.Deduction_Limit,
            Activity: ite.Activity,
          });
        });
      });
      return business_supplier_article;
    },
  },
  methods: {
    //500
    jchandleRemove(file, fileList) {
      console.log(file, fileList);
      console.log("Upload change event:", file, fileList);
      const arr = fileList?.filter((i) => i.uid !== file.uid);
      console.log(arr);
      this.$set(this, "jcfileList", arr);
      file.Row_Status = 1;
      let lArray = new Array();
      lArray.push(file);
      let lJSONObject_business_article_pic = new Object();
      lJSONObject_business_article_pic.business_article_pic = lArray; //换表
      let lJSONObject_DataSet = new Object(); //Modify
      lJSONObject_DataSet.Modify = lJSONObject_business_article_pic; //换表
      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    xhandleRemove(file, fileList) {
      console.log(file, fileList);
      console.log("Upload change event:", file, fileList);
      const arr = fileList?.filter((i) => i.uid !== file.uid);
      console.log(arr);
      this.$set(this, "xfileList", arr);
      file.Row_Status = 1;
      let lArray = new Array();
      lArray.push(file);
      let lJSONObject_business_article_pic = new Object();
      lJSONObject_business_article_pic.business_article_pic = lArray; //换表
      let lJSONObject_DataSet = new Object(); //Modify
      lJSONObject_DataSet.Modify = lJSONObject_business_article_pic; //换表
      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    zhandleRemove(file, fileList) {
      console.log(file, fileList);
      console.log(this.zfileList);

      console.log("Upload change event:", file, fileList);
      const arr = fileList?.filter((i) => i.uid !== file.uid);
      console.log(arr);
      this.$set(this, "zfileList", arr);
      file.Row_Status = 1;
      let lArray = new Array();
      lArray.push(file);
      let lJSONObject_business_article_pic = new Object();
      lJSONObject_business_article_pic.business_article_pic = lArray; //换表
      let lJSONObject_DataSet = new Object(); //Modify
      lJSONObject_DataSet.Modify = lJSONObject_business_article_pic; //换表
      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    gghandleRemove(index) {
      console.log(index);
      // return;
      this.upLoadFilesList[index] = new Array();
      this.business_article_specifications[index].Picture_URL = "";
      this.$set(this, "upLoadFilesList", [...this.upLoadFilesList]);
      console.log(this.upLoadFilesList);
    },
    gghandleBeforeUpload(file, index) {
      const maxSize = 500 * 1024; // 500KB
      if (file.size > maxSize) {
        this.$message.error(
          "图片大小超出限制，最大允许上传 500KB 的图片，请压缩后重新上传"
        );
        return;
      }
      console.log(file, index);

      // return;
      const reader = new FileReader();
      reader.onload = (e) => {
        const newFile = {
          name: file.name,
          url: e.target.result, // 预览URL
          uid: file.uid,
          Add: 1,
          // 可以添加其他属性，如上传状态等
        };
        this.upLoadFilesList[index] = new Array();
        console.log(this.upLoadFilesList[index]);
        this.upLoadFilesList[index].push(newFile);
        this.$set(this, "upLoadFilesList", [...this.upLoadFilesList]);

        console.log(888, this.upLoadFilesList);

        // console.log(newFile);
        const _this = this;
        $.ajax({
          // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
          url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          type: "POST", // 注意HTTP方法应该大写
          contentType: "application/json", // 设置请求体的媒体类型为application/json
          data: JSON.stringify(this.upLoadFilesList[index]), // 将数据序列化为JSON字符串
          success: function (Result) {
            console.log(Result);
            console.log(_this.upLoadFilesList[index]);

            let base64Image = _this.upLoadFilesList[index][0].url;
            let dataIndex = base64Image.indexOf("data:");
            let base64Index = base64Image.indexOf(";base64,");
            let substring = base64Image.substring(dataIndex + 5, base64Index);
            let ls_split = substring.split("/");
            _this.business_article_specifications[index].Picture_URL =
              _this.upLoadFilesList[index][0].uid + "." + ls_split[1];
            // upLoadFilesList.push(new Array());
            // let lJSONObject_business_article_pic = new Object();
            // lJSONObject_business_article_pic.business_article_pic =
            //   _this.upLoadFilesList[index];

            // _this.form2[index] = _this.upLoadFilesList[index];
            // _this.upLoadFilesList[index];
            console.log(111, _this.business_article_specifications[index]);
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
          },
          dataType: "json", // 预期服务器返回的数据类型
        });
      };
      reader.readAsDataURL(file);
      // console.log(this.fmfileList);

      // 返回false以阻止自动上传
      return false;
    },
    gghandleChange(file, fileList) {
      // 这个方法现在主要用于调试或处理其他上传后的逻辑
      // 注意：这里的fileList参数与:file-list绑定的fileList不是同一个对象
      // :file-list绑定的fileList是组件内部维护的，而这里的fileList是上传事件提供的
      console.log("Upload change event:", file, fileList);
    },
    jchandleChange(file, fileList) {
      // 这个方法现在主要用于调试或处理其他上传后的逻辑
      // 注意：这里的fileList参数与:file-list绑定的fileList不是同一个对象
      // :file-list绑定的fileList是组件内部维护的，而这里的fileList是上传事件提供的
      console.log("Upload change event:", file, fileList);
    },
    //检测图
    jchandleBeforeUpload(file, fileList) {
      const maxSize = 500 * 1024; // 500KB
      if (file.size > maxSize) {
        this.$message.error(
          "图片大小超出限制，最大允许上传 500KB 的图片，请压缩后重新上传"
        );
        return;
      }
      let Article_SerialNumber = sessionStorage.getItem("Article_SerialNumber");
      console.log(this.jcfileList);
      // 生成预览URL并添加到fileList中
      const reader = new FileReader();
      reader.onload = (e) => {
        //调用存储的接口放在onload中，存在异步操作
        const newFile = {
          name: file.name,
          url: e.target.result, // 预览URL
          uid: file.uid, //添加uid
          Add: 1,
          delete: 1,
          Article_SerialNumber: Article_SerialNumber,
          // 可以添加其他属性，如上传状态等
        };
        this.jcfileList.push(newFile);
        console.log(this.jcfileList);
        let arrjc = this.jcfileList.filter((item) => {
          if (item.uid == file.uid) {
            item.uid = "jc_" + item.uid;
            console.log(item);
            return item;
          }
          // return item;
        });
        console.log("=====", arrjc);
        // return;
        // for (let i = 0; i < this.jcfileList.length; i++) {
        //   this.jcfileList[i].uid = "jc_" + this.jcfileList[i].uid;
        // }
        // console.log(this.jcfileList);
        // let lArray = new Array();
        // lArray = this.jcfileList?.filter((i) => i.Add);
        // console.log(lArray);

        $.ajax({
          // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
          url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          type: "POST", // 注意HTTP方法应该大写
          contentType: "application/json", // 设置请求体的媒体类型为application/json
          data: JSON.stringify(arrjc), // 将数据序列化为JSON字符串
          success: function (Result) {
            console.log(Result);
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
          },
          dataType: "json", // 预期服务器返回的数据类型
        });
        // return;
        // $.ajax({
        //   // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
        //   url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
        //   // url: "http://192.168.10.79:8087/store/photo",
        //   type: "POST", // 注意HTTP方法应该大写
        //   contentType: "application/json", // 设置请求体的媒体类型为application/json
        //   data: JSON.stringify(this.jcfileList), // 将数据序列化为JSON字符串
        //   success: function (Result) {
        //     console.log(Result);
        //   },
        //   complete: function (XMLHttpRequest) {
        //     requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
        //   },
        //   dataType: "json", // 预期服务器返回的数据类型
        // });
      };
      reader.readAsDataURL(file);
      // 返回false以阻止自动上传

      return false;
    },
    xhandleChange(file, fileList) {
      // 这个方法现在主要用于调试或处理其他上传后的逻辑
      // 注意：这里的fileList参数与:file-list绑定的fileList不是同一个对象
      // :file-list绑定的fileList是组件内部维护的，而这里的fileList是上传事件提供的
      console.log("Upload change event:", file, fileList);
    },
    //详情图
    xhandleBeforeUpload(file, fileList) {
      const maxSize = 500 * 1024; // 500KB
      if (file.size > maxSize) {
        this.$message.error(
          "图片大小超出限制，最大允许上传 500KB 的图片，请压缩后重新上传"
        );
        return;
      }
      let Article_SerialNumber = sessionStorage.getItem("Article_SerialNumber");
      console.log(this.xfileList);
      // 生成预览URL并添加到fileList中
      const reader = new FileReader();
      reader.onload = (e) => {
        //调用存储的接口放在onload中，存在异步操作
        const newFile = {
          name: file.name,
          url: e.target.result, // 预览URL
          uid: file.uid, //添加uid
          Add: 1,
          delete: 1,
          Article_SerialNumber: Article_SerialNumber,
          // 可以添加其他属性，如上传状态等
        };
        this.xfileList.push(newFile);
        console.log(this.xfileList);

        let arrD = this.xfileList.filter((item) => {
          if (item.uid == file.uid) {
            item.uid = "D_" + item.uid;
            console.log(item);
            return item;
          }
          // return item;
        });
        console.log("=====", arrD);
        // return;
        // this.xfileList?.filter((i) => {
        //   if (i.Add) {
        //     console.log(i);

        //     i.uid = "D_" + i.uid;

        $.ajax({
          // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
          url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          type: "POST", // 注意HTTP方法应该大写
          contentType: "application/json", // 设置请求体的媒体类型为application/json
          data: JSON.stringify(arrD), // 将数据序列化为JSON字符串
          success: function (Result) {
            console.log(Result);
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
          },
          dataType: "json", // 预期服务器返回的数据类型
        });
        // }
        // });

        // for (let i = 0; i < this.fileList.length; i++) {
        //   this.xfileList[i].uid = "D_" + this.xfileList[i].uid;
        // }
        // console.log(this.xfileList);
        // let lArray = new Array();
        // lArray = this.xfileList?.filter((i) => i.Add);
        // console.log(lArray);

        // $.ajax({
        //   // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
        //   url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
        //   // url: "http://192.168.10.79:8087/store/photo",
        //   type: "POST", // 注意HTTP方法应该大写
        //   contentType: "application/json", // 设置请求体的媒体类型为application/json
        //   data: JSON.stringify(lArray), // 将数据序列化为JSON字符串
        //   success: function (Result) {
        //     console.log(Result);
        //   },
        //   complete: function (XMLHttpRequest) {
        //     requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
        //   },
        //   dataType: "json", // 预期服务器返回的数据类型
        // });
        // return;
        // $.ajax({
        //   // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
        //   url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
        //   // url: "http://192.168.10.79:8087/store/photo",
        //   type: "POST", // 注意HTTP方法应该大写
        //   contentType: "application/json", // 设置请求体的媒体类型为application/json
        //   data: JSON.stringify(this.xfileList), // 将数据序列化为JSON字符串
        //   success: function (Result) {
        //     console.log(Result);
        //   },
        //   complete: function (XMLHttpRequest) {
        //     requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
        //   },
        //   dataType: "json", // 预期服务器返回的数据类型
        // });
      };
      reader.readAsDataURL(file);
      // 返回false以阻止自动上传

      return false;
    },
    //主图Z
    zhandleBeforeUpload(file, fileList) {
      const maxSize = 500 * 1024; // 500KB
      if (file.size > maxSize) {
        this.$message.error(
          "图片大小超出限制，最大允许上传 500KB 的图片，请压缩后重新上传"
        );
        return;
      }
      console.log(file, fileList);

      let Article_SerialNumber = sessionStorage.getItem("Article_SerialNumber");
      console.log(this.zfileList);
      // 生成预览URL并添加到fileList中
      const reader = new FileReader();
      reader.onload = (e) => {
        //调用存储的接口放在onload中，存在异步操作
        const newFile = {
          name: file.name,
          url: e.target.result, // 预览URL
          uid: file.uid, //添加uid
          Add: 1,
          delete: 1,
          Article_SerialNumber: Article_SerialNumber,
          // 可以添加其他属性，如上传状态等
        };
        this.zfileList.push(newFile);
        console.log(this.zfileList);
        // file.uid = "M_" + file.uid;
        // let lArray = new Array();
        // lArray.push(file);
        // 筛选带有 'M' 的图片

        let arrM = this.zfileList.filter((item) => {
          if (item.uid == file.uid) {
            item.uid = "M_" + item.uid;
            console.log(item);
            return item;
          }
          // return item;
        });
        console.log("=====", arrM);

        // let arrM = this.zfileList?.filter((i) => i.Add);
        // console.log(lArray);

        // return;

        $.ajax({
          // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
          url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          type: "POST", // 注意HTTP方法应该大写
          contentType: "application/json", // 设置请求体的媒体类型为application/json
          data: JSON.stringify(arrM), // 将数据序列化为JSON字符串
          success: function (Result) {
            console.log(Result);
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
          },
          dataType: "json", // 预期服务器返回的数据类型
        });
      };

      // };
      reader.readAsDataURL(file);
      // 返回false以阻止自动上传

      return false;
    },
    zhandleChange(file, fileList) {
      // 这个方法现在主要用于调试或处理其他上传后的逻辑
      // 注意：这里的fileList参数与:file-list绑定的fileList不是同一个对象
      // :file-list绑定的fileList是组件内部维护的，而这里的fileList是上传事件提供的
      console.log("Upload change event:", file, fileList);
    },
    fhandleRemove(file, fileList) {
      let Article_SerialNumber = sessionStorage.getItem("Article_SerialNumber");
      console.log(Article_SerialNumber);
      console.log(file, fileList);

      console.log(this.fileList);
      this.fileList.splice(0, 1);
      const that = this;
      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/getArticalSpecificationByEnterpriseAndArticleNumber",
        type: "get",
        data: {
          Article_SerialNumber: Article_SerialNumber,

        },
        success: function (Result) {
          console.log(Result);
          Result.business_article_info[0].Picture_URL = "";
          console.log(Result);
          let lJSONObject_business_article_info = new Object();
          lJSONObject_business_article_info.business_article_info =
            Result.business_article_info; //换表
          let lJSONObject_DataSet = new Object(); //Modify
          lJSONObject_DataSet.Modify = lJSONObject_business_article_info; //换表
          console.log(lJSONObject_DataSet);

          // return;
          $.ajax({
            // headers: requestHeaders(),
            // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
            url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
            type: "POST",
            data: {
              Data: JSON.stringify(lJSONObject_DataSet),
            },
            success: function (Result) {
              that.form.Picture_URL_Original = "";
              console.log(Result);
            },
            complete: function (XMLHttpRequest) {
              requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
            },
            dataType: "json",
          });
        },
        complete: function (XMLHttpRequest) {
          // requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    chandleChange(file, fileList) {
      // 这个方法现在主要用于调试或处理其他上传后的逻辑
      // 注意：这里的fileList参数与:file-list绑定的fileList不是同一个对象
      // :file-list绑定的fileList是组件内部维护的，而这里的fileList是上传事件提供的
      console.log("Upload change event:", file, fileList);
    },
    handleBeforeUpload(file, fileList) {
      const maxSize = 500 * 1024; // 500KB
      if (file.size > maxSize) {
        this.$message.error(
          "图片大小超出限制，最大允许上传 500KB 的图片，请压缩后重新上传"
        );
        return;
      }
      console.log(file, fileList);
      console.log(this.fileList);

      // 生成预览URL并添加到fileList中
      const reader = new FileReader();
      reader.onload = (e) => {
        //调用存储的接口放在onload中，存在异步操作
        const newFile = {
          name: file.name,
          url: e.target.result, // 预览URL
          uid: file.uid, //添加uid
          Add: 1,
          // 可以添加其他属性，如上传状态等
        };
        this.fileList.push(newFile);
        for (let i = 0; i < this.fileList.length; i++) {
          this.fileList[i].uid = "C_" + this.fileList[i].uid;
        }
        console.log(this.fileList);

        // return;
        $.ajax({
          // headers: requestHeaders(), // 确保这个函数返回正确的头部信息
          url: "https://service.kdddy.cn/donghuiForRequest/store/photo",
          // url: "http://192.168.10.79:8087/store/photo",
          type: "POST", // 注意HTTP方法应该大写
          contentType: "application/json", // 设置请求体的媒体类型为application/json
          data: JSON.stringify(this.fileList), // 将数据序列化为JSON字符串
          success: function (Result) {
            console.log(Result);
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest); // 确保这个函数在config/config.js中定义
          },
          dataType: "json", // 预期服务器返回的数据类型
        });
      };
      reader.readAsDataURL(file);
      // 返回false以阻止自动上传

      return false;
    },
    cjd() {
      let Article_SerialNumber = sessionStorage.getItem("Article_SerialNumber");
      console.log(Article_SerialNumber);
      console.log(Article_SerialNumber, "Article_SerialNumber");
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        type: "POST",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
        data: {
          Data: "base_ArticlePaymentDetails", //表名
          Condition: "Article_SerialNumber='" + Article_SerialNumber + "'",
          // id: ls_RequesterlD
        },
        success: (res) => {
          console.log(res, "--------------");
          for (let i = 0; i < res.length; i++) {
            if (res[i].Node_Name == "定金") {
              _this.dj = res[i];
            } else if (res[i].Node_Name == "发货") {
              _this.fh = res[i];
            } else if (res[i].Node_Name == "到货") {
              _this.dh = res[i];
            } else {
              _this.wk = res[i];
            }
          }
        },
        fail: (err) => {
          console.error(err);
        },
      });
    },
    // 商品规格
    spgg() {
      let Article_SerialNumber = sessionStorage.getItem("Article_SerialNumber");
      console.log(Article_SerialNumber);

      const _this = this;
      $.ajax({
        headers: {
          AccessToken: $.cookie("token"), //会将数据转换为query string
        },
        url: "https://service.kdddy.cn/donghui/clientOperation/getArticalSpecificationByEnterpriseAndArticleNumber",
        type: "get",
        data: {
          Article_SerialNumber: Article_SerialNumber,
          Edit:'1'
        },
        success: function (Result) {
          console.log("===>", Result);
          _this.business_article_specifications = Result.business_article_specifications;
          for (let i = 0; i < Result.business_article_specifications.length;i++) {
            let lArray_URL = new Array();
            let lJSONObject_Picture_Record = new Object();
            lJSONObject_Picture_Record.url = `https://www.kdddy.cn/Image/${Result.business_article_specifications[i].Picture_URL}`;
            lArray_URL.push(lJSONObject_Picture_Record);
            console.log("url", lArray_URL);
            if (i == 0) {
              _this.upLoadFilesList[i] = lArray_URL;
            } else {
              _this.upLoadFilesList.push(new Array());
              _this.upLoadFilesList[i] = lArray_URL;
            }
          }
        },
        complete: function (XMLHttpRequest) {
          // requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    //通过预包装商品id查看规格
    spxx() {
      let Article_SerialNumber = sessionStorage.getItem("Article_SerialNumber");
      console.log(Article_SerialNumber);

      const _this = this;
      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        // url: "https://service.kdddy.cn/donghuiForRequest/get/VarietyDetail",
        url: "https://service.kdddy.cn/donghui/clientOperation/getArticalSpecificationByEnterpriseAndArticleNumber",
        type: "get",
        data: {
          Article_SerialNumber: Article_SerialNumber,
        },
        success: function (Result) {
          console.log(Result);

          _this.form = Result.business_article_info[0];
          console.log(_this.form);
          _this.VarietyID = Result.business_article_info[0].VarietyName;
          _this.GradeID = Result.business_article_info[0].GradeName;
          _this.is_Article_Type = Result.business_article_info[0].Article_Type;

          let lArray_URL = new Array();
          let lJSONObject_Picture_Record = new Object();
          lJSONObject_Picture_Record.url = `https://www.kdddy.cn/Image/${Result.business_article_info[0].Picture_URL}`;
          lArray_URL.push(lJSONObject_Picture_Record);
          _this.fileList = lArray_URL;

          // 筛选带有 'M' 的图片
          let arrM = Result.business_article_pic.filter(
            (item) => item.Picture_URL && item.Picture_URL.includes("M")
          );

          // 筛选带有 'D' 的图片
          let arrD = Result.business_article_pic.filter(
            (item) => item.Picture_URL && item.Picture_URL.includes("D")
          );

          // 筛选带有 'jc' 的图片
          let arrjc = Result.business_article_pic.filter(
            (item) => item.Picture_URL && item.Picture_URL.includes("jc")
          );
          console.log("带有M的数组:", arrM);
          console.log("带有D的数组:", arrD);
          console.log("带有M的数组:", arrjc);
          // 遍历 business_article_pic 数组，将 Picture_URL 改名为 uid
          arrM = arrM.map((item) => {
            console.log(item);

            // 创建一个新对象，将 Picture_URL 的值赋给 uid
            const newItem = {
              ...item,
              url: `https://www.kdddy.cn/Image/${item.Picture_URL}`,
            };
            // 删除原来的 Picture_URL 属性
            // delete newItem.Picture_URL;

            return newItem;
          });
          arrD = arrD.map((item) => {
            console.log(item);

            // 创建一个新对象，将 Picture_URL 的值赋给 uid
            const newItem = {
              ...item,
              url: `https://www.kdddy.cn/Image/${item.Picture_URL}`,
            };
            // 删除原来的 Picture_URL 属性
            // delete newItem.Picture_URL;

            return newItem;
          });
          // 遍历 business_article_pic 数组，将 Picture_URL 改名为 uid
          arrjc = arrjc.map((item) => {
            console.log(item);

            // 创建一个新对象，将 Picture_URL 的值赋给 uid
            const newItem = {
              ...item,
              url: `https://www.kdddy.cn/Image/${item.Picture_URL}`,
            };
            // 删除原来的 Picture_URL 属性
            // delete newItem.Picture_URL;

            return newItem;
          });
          console.log(arrM);
          _this.zfileList = arrM;
          console.log(_this.zfileList);

          console.log(arrD);
          _this.xfileList = arrD;
          console.log(_this.xfileList);

          console.log(arrjc);
          _this.jcfileList = arrjc;
          console.log(_this.jcfileList);
        },
        complete: function (XMLHttpRequest) {
          // requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    submitForm() {
      let Enterprise_Info_SerialNumber = sessionStorage.getItem(
        "Enterprise_Info_SerialNumber"
      );
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        type: "POST",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        data: {
          Data: "enterprise_info", //表名
          Condition:
            "Enterprise_Info_SerialNumber = '" +
            Enterprise_Info_SerialNumber +
            "'",
        },
        success: function (Result) {
          console.log(Result);
          // if (Result[0].Need_Review == "0") {
          sessionStorage.setItem("Need_Review", Result[0].Need_Review);
          // }
          _this.sub();
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    sub(formName) {
      console.log(formName);
      const _this = this;
      console.log(this.business_article_specifications);

      let Need_Review = sessionStorage.getItem("Need_Review");
      console.log(Need_Review);

      if (Need_Review == "1") {
        this.business_article_specifications.forEach((i) => {
          console.log(i);
          i.Row_Status = "1";
        });
      } else {
        this.business_article_specifications.forEach((i) => {
          console.log(i);
          i.Row_Status = "0";
        });
      }
      // 设置表单数据
      _this.form.Article_Type = _this.is_Article_Type;
      for (let i = 0; i < _this.iJSONArray_Variety.length; i++) {
        if (_this.VarietyID === _this.iJSONArray_Variety[i].VarietyID) {
          console.log(_this.iJSONArray_Variety[i].VarietyName, "----------");
          _this.form.VarietyName = _this.iJSONArray_Variety[i].VarietyName;
        }
      }
      for (let i = 0; i < _this.iJSONArray_VarietyGrade.length; i++) {
        if (_this.GradeID === _this.iJSONArray_VarietyGrade[i].GradeID) {
          console.log(_this.iJSONArray_VarietyGrade[i].GradeName, "*********");
          _this.form.GradeName = _this.iJSONArray_VarietyGrade[i].GradeName;
        }
      }

      // 处理收款节点数据
      let lJSONArray_fkzq = [_this.dj, _this.fh, _this.dh, _this.wk];
      console.log(lJSONArray_fkzq);
      // lJSONArray_fkzq.forEach((element) => {
      //   delete element.Operation_Datetime;
      //   delete element.Operation_Datetime_Original;
      // });
      // // return;
      // // 删除不必要的表单字段
      delete _this.form.Operation_Datetime;
      delete _this.form.Operation_Datetime_Original;
      console.log(this.form);

      // 处理规格数据
      let lJSONObject_business_article_specifications = {
        business_article_specifications:
          _this.business_article_specifications?.filter((i) => !i.ADD),
        base_ArticlePaymentDetails: lJSONArray_fkzq,
      };
      _this.Add = _this.business_article_specifications?.filter((i) => i.ADD);
      _this.form.Children = lJSONObject_business_article_specifications;

      console.log(lJSONObject_business_article_specifications);

      // return;
      // 封装文件处理逻辑
      function processFileList(fileList) {
        return fileList?.map((i) => {
          if (i.Add) {
            let base64Image = i.url;
            let dataIndex = base64Image.indexOf("data:");
            let base64Index = base64Image.indexOf(";base64,");
            let substring = base64Image.substring(dataIndex + 5, base64Index);
            let ls_split = substring.split("/");
            i.Picture_URL = i.uid + "." + ls_split[1];
          }
          return i;
        });
      }

      // 处理文件列表
      _this.fileList?.map((i) => {
        if (i.Add) {
          let base64Image = i.url;
          let dataIndex = base64Image.indexOf("data:");
          let base64Index = base64Image.indexOf(";base64,");
          let substring = base64Image.substring(dataIndex + 5, base64Index);
          let ls_split = substring.split("/");
          _this.form.Picture_URL = i.uid + "." + ls_split[1];
        }
        return i;
      });

      let c = processFileList(_this.zfileList);
      let d = processFileList(_this.xfileList);
      let jcArr = processFileList(_this.jcfileList);

      // 计算支付比例总和
      let totalPaymentRatio = 0; // 总和
      let definedCount = 0; // 计数
      for (let i = 0; i < lJSONArray_fkzq.length; i++) {
        console.log(definedCount);
        if (lJSONArray_fkzq[i].Payment_Ratio !== "") {
          totalPaymentRatio += parseInt(lJSONArray_fkzq[i].Payment_Ratio);
          definedCount++;
        }
      }
      console.log(definedCount, "jishu");
      console.log(totalPaymentRatio);

      // return;
      // 合并图片数据
      let pic = [...(c || []), ...(d || []), ...(jcArr || [])];
      console.log(pic);

      // 处理图片数据
      lJSONObject_business_article_specifications.business_article_pic = pic?.filter((i) => !i.Add);
      let business_article_log = [];
      this.business_article_specifications.forEach((i) => {
        business_article_log.push({
          Article_Specifications_SerialNumber:i.Article_Specifications_SerialNumber,
          Row_Status: i.Row_Status
        })
      });

      let lJSONObject_business_article_specifications2 = {
        business_article_pic: pic?.filter((i) => i.Add),
        business_article_specifications: _this.Add,
        business_article_log,
      };
      
      // 表单校验
      if (this.form.Article_Name === "") {
        this.$message({
          message: "请输入商品名称",
          type: "warning",
        });
        return;
      } else if (this.VarietyID === "") {
        this.$message({
          message: "请选择品种",
          type: "warning",
        });
        return;
      } else if (this.GradeID === "") {
        this.$message({
          message: "请选择等级",
          type: "warning",
        });
        return;
      } else if (this.form.Brand_SerialNumber === "") {
        this.$message({
          message: "请选择商品品牌，如为空请先去维护品牌信息",
          type: "warning",
        });
        return;
      } else if (this.form.Category_SerialNumber === "") {
        this.$message({
          message: "请选择商品类型",
          type: "warning",
        });
        return;
      } else if (this.is_Article_Type === "") {
        this.$message({
          message: "请选择商品包装信息",
          type: "warning",
        });
        return;
      } else if (this.fileList.length === 0) {
        this.$message({
          message: "您还未上传商品封面图片",
          type: "warning",
        });
        return;
      }

      // 收款方式校验
      let a = 0;
      lJSONArray_fkzq.forEach((element) => {
        if (
          element.Payment_Ratio === "" ||
          element.Payment_Ratio === undefined
        ) {
          a++;
        }
      });
      console.log(a, "jige");
      if (a === 4) {
        this.$message.error("请您输入收款方式");
        return;
      } else {
        // 支付比例校验
        if (totalPaymentRatio > 100) {
          this.$message.error("支付比例的总和不能超过100");
          return;
        } else if (definedCount === 1 && totalPaymentRatio < 100) {
          this.$message.error("只有一个支付比例时，支付比例不能低于100");
          return;
        } else if (definedCount !== 1 && totalPaymentRatio < 100) {
          this.$message.error("支付比例的总和不能低于100");
          return;
        }
      }
      console.log(totalPaymentRatio);
      lJSONArray_fkzq.forEach((element) => {
        console.log(element);
        if (element.Payment_Ratio !== "") {
          element.Payment_Ratio = parseInt(element.Payment_Ratio);
        }
        if (element.Payment_Ratio == 0) {
          element.Payment_Ratio = "";
        }
        if (element.Payment_Ratio == "null") {
          element.Payment_Ratio = "";
        }
        if (element.Payment_Ratio !== "" && element.Excepted_Days == "") {
          element.Excepted_Days = 0;
        }
      });
      console.log(lJSONArray_fkzq);
      // return;
      // 构建请求数据
      let lJSONObject_business_article_info = {
        business_article_info: [_this.form],
      };
      let lJSONObject_DataSet = {
        Modify: lJSONObject_business_article_info,
        Add: lJSONObject_business_article_specifications2,
      };
      console.log(lJSONObject_DataSet, "lJSONObject_DataSet");
      console.log(this.fileList, "封面图片");

      
      // return;
      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status === "success") {
            _this.$message.success("提交成功");
            window.history.go(-1);
          } else {
            _this.$message.error("提交失败，请稍后再试");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    getcategoryList() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        type: "POST",
        data: {
          Data: "business_category",
          Condition: "Row_Status='0'",
        },
        success: function (Result) {
          console.log(Result, "--------------");

          _this.category = Result;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    getbrandList() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        type: "POST",
        data: {
          Data: "business_brand",
          Condition: "Row_Status='0' AND Enterprise_Number='"+ $.cookie('enterprise') +"'",
        },
        success: function (Result) {
          console.log(Result, "--------------");

          _this.brand = Result;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    getbrandList() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        type: "POST",
        data: {
          Data: "business_brand",
          Condition: "Row_Status='0' AND Enterprise_Number='"+ $.cookie('enterprise') +"'",
        },
        success: function (Result) {
          // console.log(Result, "--------------");

          _this.brand = Result;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    getVarietyList() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        type: "POST",
        data: {
          Data: "base_EdibleMushroomVariety",
          Condition: "Row_Status='0'",
        },
        success: function (Result) {
          // console.log(Result, "--------------");

          _this.iJSONArray_Variety = Result;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    showFileList: function (index) {
      // return function (url) {
      //   return url ? [url] : [];
      // };
      console.log("index", index, this.upLoadFilesList[index]);

      return this.upLoadFilesList[index];
    },
    handleChange(value) {
      console.log(value, "value");

      // return;
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        type: "POST",
        data: {
          Data: "base_EdibleMushroomGrade",
          Condition: "Row_Status='0' AND VarietyID='" + _this.VarietyID + "'",
        },
        success: function (Result) {
          // _this.tableData = Result.Rows;
          _this.iJSONArray_VarietyGrade = new Array(); //清空数组中原有值
          _this.iJSONArray_VarietyGrade = Result;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    // getData() {
    //   const that = this;
    //   const Condition = "Row_Status='0'";
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_brand",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.brand = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_category",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.category = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_series",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.series = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_item",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.item = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_supplier_info",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.supplier = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_article_unit",
    //       Condition,
    //     },
    //     success: function (res) {
    //       that.unit = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/getAllClassify`,
    //     type: "GET",
    //     success: function (data) {
    //       that.classify = data;
    //     },
    //     complete: function (XMLHttpRequest) {
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    //   $.ajax({
    //     headers: requestHeaders(),
    //     url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
    //     type: "POST",
    //     data: {
    //       Data: "business_activity",
    //       Condition: "Row_Status <> '1' AND End_Date > NOW()",
    //     },
    //     success: function (res) {
    //       that.activity = res;
    //     },
    //     error: function () {
    //       //   that.$message.error("操作失败，请稍后再试");
    //     },
    //     complete: function (XMLHttpRequest) {
    //       that.loading = false;
    //       requestPretreatment(XMLHttpRequest);
    //     },
    //     dataType: "json",
    //   });
    // },
    // submitForm(formName) {
    //   const that = this;
    //   this.$refs[formName].validate((valid) => {
    //     if (valid) {
    //       if (!that.form.Article_Code) {
    //         that
    //           .$confirm(
    //             "当前商品未录入商品编号可能会影响商品唯一性，是否继续?",
    //             "提示",
    //             {
    //               confirmButtonText: "确定",
    //               cancelButtonText: "取消",
    //               type: "warning",
    //             }
    //           )
    //           .then(() => {
    //             that.add({});
    //           })
    //           .catch(() => {});
    //       } else {
    //         that.add({
    //           business_article_config: [
    //             { Article_Code: this.form.Article_Code },
    //           ],
    //         });
    //       }
    //     } else {
    //       that.$message({
    //         message: sumberError,
    //         type: "warning",
    //       });
    //       return false;
    //     }
    //   });
    // },
    add(code) {
      const that = this;
      let obj = deepClone(that.form);
      obj.Children.business_article_group = that.business_article_group;
      this.loading = true;
      that.Main_Image.filter((i) => i.id == 0).forEach((item, index) => {
        //主图
        obj.Children.business_article_pic.push({
          Article_PicNumber: "",
          Article_SerialNumber: "",
          Picture_Type: "0",
          Picture_Order: index + 1,
          Picture_URL: item.Picture_URL,
        });
      });
      that.Detail_Image.filter((i) => i.id == 0).forEach((item, index) => {
        //详情图
        obj.Children.business_article_pic.push({
          Article_PicNumber: "",
          Article_SerialNumber: "",
          Picture_Type: "1",
          Picture_Order: index + 1,
          Picture_URL: item.Picture_URL,
        });
      });
      obj.ClassifyJSON = JSON.stringify(that.business_article_classify);
      that.business_article_classify.forEach((Array) => {
        Array.forEach((i) => {
          if (
            !obj.Children.business_article_classify.some(
              (j) => j.Classify_SerialNumber == i
            )
          ) {
            obj.Children.business_article_classify.push({
              Article_Classify_SerialNumber: "",
              Article_SerialNumber: "",
              Classify_SerialNumber: i,
              Parent_SerialNumber: Array[0],
            });
          }
        });
      });
      //提交
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({
            Add: {
              business_article_info: [obj],
              ...code,
              base_operation_log: [
                generateLog(
                  "添加商品主数据",
                  "平台端操作",
                  "business_article_info",
                  JSON.stringify({ Add: { business_article_info: [obj] } })
                ),
              ],
            },
          }),
        },
        success: function (res) {
          if (res.Status === "success") {
            if (that.business_supplier_article.length > 0) {
              that.$message.success("商品添加成功,开始配置供应商");
              that.submitSupplier(); //提交供应商信息
            } else {
              that.loading = false;
              that.$message.success("提交成功");
              window.history.go(-1);
            }
          } else {
            that.loading = false;
            // that.$message.error("提交失败，请稍后再试");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitSupplier() {
      //提交供应商
      const that = this;
      let sql = "";
      this.business_supplier_article.forEach((item) => {
        if (sql) {
          sql =
            sql +
            "\r\nOR business_article_info.Article_Name = '" +
            item.Article_Name +
            "'" +
            "\r\nAND business_article_specifications.Specifications_Name = '" +
            item.Specifications_Name +
            "'" +
            "\r\nAND business_article_info.Brand_SerialNumber = '" +
            item.Brand_SerialNumber +
            "'";
        } else {
          sql =
            " business_article_info.Article_Name = '" +
            item.Article_Name +
            "'" +
            "\r\nAND business_article_specifications.Specifications_Name = '" +
            item.Specifications_Name +
            "'" +
            "\r\nAND business_article_info.Brand_SerialNumber = '" +
            item.Brand_SerialNumber +
            "'";
        }
      });
      if (sql) {
        sql = `WHERE ${sql}`;
      }
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
        type: "POST",
        data: {
          SQLSerialNumber: "A_business_article_specifications2",
          Condition: "",
          ExtensionCondition: window.btoa(unescape(encodeURIComponent(sql))),
        },
        success: function (Result) {
          if (Result.length > 0) {
            //执行添加
            let business_supplier_article = that.business_supplier_article;
            let base_operation_log = [];
            business_supplier_article.forEach((item) => {
              let obj = Result.filter(
                (i) =>
                  i.Specifications_Name == item.Specifications_Name &&
                  i.Article_Name == item.Article_Name &&
                  i.Brand_SerialNumber == item.Brand_SerialNumber
              )[0];
              item.Article_SerialNumber = obj.Article_SerialNumber;
              item.Article_Specifications_SerialNumber =
                obj.Article_Specifications_SerialNumber;
              item.Supplier_Article_SerialNumber =
                item.Supplier_SerialNumber +
                "-" +
                obj.Article_Specifications_SerialNumber;
              //日志
              base_operation_log.push(
                generateLog(
                  "添加供应商经营商品",
                  "平台端操作",
                  "business_supplier_article",
                  JSON.stringify({ Add: { business_supplier_article: [item] } })
                )
              );
            });
            $.ajax({
              headers: requestHeaders(),
              url: `${BASE_URL2}/generalBusiness/generalSave`,
              type: "POST",
              data: {
                Data: JSON.stringify({
                  Add: { business_supplier_article, base_operation_log },
                }),
              },
              success: function (res) {
                if (res.Status === "success") {
                  //添加采购价格单
                  if (
                    business_supplier_article.filter(
                      (i) =>
                        !isNaN(i.Purchase_Unit_Price) &&
                        i.Purchase_Unit_Price > 0
                    ).length > 0
                  ) {
                    that.$message.success("开始添加采购价格单");
                    that.submitPurchase(business_supplier_article);
                  } else if (
                    business_supplier_article.filter(
                      (i) =>
                        !isNaN(i.Sales_Unit_Price) && i.Sales_Unit_Price > 0
                    ).length > 0
                  ) {
                    //添加销售价格单
                    that.$message.success("开始添加销售价格单");
                    that.submitSales(business_supplier_article);
                  } else if (
                    business_supplier_article.filter(
                      (i) => !isNaN(i.Quantity) && i.Quantity > 0
                    ).length > 0
                  ) {
                    that.$message.success("开始添加每日库存");
                    that.submitStock(business_supplier_article);
                  } else if (
                    business_supplier_article.filter(
                      (i) =>
                        i.Pionts.length > 0 &&
                        !isNaN(i.Deduction_Limit) &&
                        i.Deduction_Limit > 0
                    ).length > 0
                  ) {
                    that.$message.success("开始配置积分方案");
                    that.submitPointsConfig(business_supplier_article);
                  } else if (
                    business_supplier_article.filter(
                      (i) => i.Activity.length > 0
                    ).length > 0
                  ) {
                    that.$message.success("开始插入活动商品");
                    that.submitActivityArticle(business_supplier_article);
                  } else {
                    that.loading = false;
                    that.$message.success("提交成功");
                    window.history.go(-1);
                  }
                } else {
                  that.loading = false;
                  //   that.$message.error("提交失败，请稍后再试");
                }
              },
              complete: function (XMLHttpRequest) {
                requestPretreatment(XMLHttpRequest);
              },
              dataType: "json",
            });
          } else {
            that.loading = false;
            that.$message.error("未知错误");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitPurchase(business_supplier_article) {
      //添加采购价格单
      const that = this;
      let business_purchase_unitprice_detail = [];
      business_supplier_article
        .filter(
          (i) => !isNaN(i.Purchase_Unit_Price) && i.Purchase_Unit_Price > 0
        )
        .forEach((item) => {
          business_purchase_unitprice_detail.push({
            Purchase_Unit_Price_Detail_SerialNumber: "",
            Purchase_Unit_Price_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Brand_SerialNumber: item.Brand_SerialNumber,
            Purchase_Unit_Price: item.Purchase_Unit_Price,
          });
        });
      let business_purchase_unitprice = [
        {
          Purchase_Unit_Price_SerialNumber: "",
          Start_Date: getYMDDate(),
          End_Date: "",
          Enterprise_Info_SerialNumber: "",
          Children: {
            business_purchase_unitprice_detail,
          },
        },
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_purchase_unitprice } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            $.ajax({
              //更新今日执行单
              headers: requestHeaders(),
              url: `${BASE_URL2}/article/generateDailyArticlePurchasePrice`,
              type: "GET",
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.status != 200) {
                  that.$message.error("每日销售价格执行单更新失败");
                }
                //添加销售价格单
                if (
                  business_supplier_article.filter(
                    (i) => !isNaN(i.Sales_Unit_Price) && i.Sales_Unit_Price > 0
                  ).length > 0
                ) {
                  that.$message.success("开始添加销售价格单");
                  that.submitSales(business_supplier_article);
                } else if (
                  business_supplier_article.filter(
                    (i) => !isNaN(i.Quantity) && i.Quantity > 0
                  ).length > 0
                ) {
                  that.$message.success("开始添加每日库存");
                  that.submitStock(business_supplier_article);
                } else if (
                  business_supplier_article.filter(
                    (i) =>
                      i.Pionts.length > 0 &&
                      !isNaN(i.Deduction_Limit) &&
                      i.Deduction_Limit > 0
                  ).length > 0
                ) {
                  that.$message.success("开始配置积分方案");
                  that.submitPointsConfig(business_supplier_article);
                } else if (
                  business_supplier_article.filter((i) => i.Activity.length > 0)
                    .length > 0
                ) {
                  that.$message.success("开始插入活动商品");
                  that.submitActivityArticle(business_supplier_article);
                } else {
                  that.loading = false;
                  that.$message.success("提交成功");
                  window.history.go(-1);
                }
              },
            });
          } else {
            that.loading = false;
            // that.$message.error("采购价格单提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitSales(business_supplier_article) {
      //添加销售价格单
      const that = this;
      let business_sales_unitprice_detail = [];
      business_supplier_article
        .filter((i) => !isNaN(i.Sales_Unit_Price) && i.Sales_Unit_Price > 0)
        .forEach((item) => {
          business_sales_unitprice_detail.push({
            Sales_Unit_Price_Detail_SerialNumber: "",
            Sales_Unit_Price_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Brand_SerialNumber: item.Brand_SerialNumber,
            Supplier_SerialNumber: item.Supplier_SerialNumber,
            Unit_Price: item.Sales_Unit_Price,
          });
        });
      let business_sales_unitprice = [
        {
          Sales_Unit_Price_SerialNumber: "",
          Start_Date: getYMDDate(),
          End_Date: "",
          Enterprise_Info_SerialNumber: "",
          Children: {
            business_sales_unitprice_detail,
            business_sales_unitprice_storescope: [
              {
                Sales_Unit_Price_StoreScope_SerialNumber: "",
                Sales_Unit_Price_SerialNumber: "",
                Store_SerialNumber: "STORE0000000001",
              },
            ],
          },
        },
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_sales_unitprice } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            $.ajax({
              //更新今日执行单
              headers: requestHeaders(),
              url: `${BASE_URL2}/article/generateDailyArticleSalesPrice`,
              type: "GET",
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.status != 200) {
                  that.$message.error("每日销售价格执行单更新失败");
                }
                //添加每日库存
                if (
                  business_supplier_article.filter(
                    (i) => !isNaN(i.Quantity) && i.Quantity > 0
                  ).length > 0
                ) {
                  that.$message.success("开始添加每日库存");
                  that.submitStock(business_supplier_article);
                } else if (
                  business_supplier_article.filter(
                    (i) =>
                      i.Pionts.length > 0 &&
                      !isNaN(i.Deduction_Limit) &&
                      i.Deduction_Limit > 0
                  ).length > 0
                ) {
                  that.$message.success("开始配置积分方案");
                  that.submitPointsConfig(business_supplier_article);
                } else if (
                  business_supplier_article.filter((i) => i.Activity.length > 0)
                    .length > 0
                ) {
                  that.$message.success("开始插入活动商品");
                  that.submitActivityArticle(business_supplier_article);
                } else {
                  that.loading = false;
                  that.$message.success("提交成功");
                  window.history.go(-1);
                }
              },
            });
          } else {
            that.loading = false;
            // that.$message.error("销售价格单提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitStock(business_supplier_article) {
      //添加每日库存
      const that = this;
      let business_supplier_article_stock_detail = [];
      business_supplier_article
        .filter((i) => !isNaN(i.Quantity) && i.Quantity > 0)
        .forEach((item) => {
          business_supplier_article_stock_detail.push({
            Supplier_Article_Stock_Detail_SerialNumber: "",
            Supplier_Article_Stock_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Brand_SerialNumber: item.Brand_SerialNumber,
            Quantity: item.Quantity,
          });
        });
      let business_supplier_article_stock = [
        {
          Supplier_Article_Stock_SerialNumber: "",
          Start_Date: getYMDDate(),
          End_Date: "",
          Enterprise_Info_SerialNumber: "",
          Children: {
            business_supplier_article_stock_detail,
          },
        },
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_supplier_article_stock } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            $.ajax({
              //更新今日执行单
              headers: requestHeaders(),
              url: `${BASE_URL2}/article/generateDailyInventory`,
              type: "GET",
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.status != 200) {
                  that.$message.error("每日库存执行单更新失败");
                }
                //添加积分配置
                if (
                  business_supplier_article.filter(
                    (i) =>
                      i.Pionts.length > 0 &&
                      !isNaN(i.Deduction_Limit) &&
                      i.Deduction_Limit > 0
                  ).length > 0
                ) {
                  that.$message.success("开始配置积分方案");
                  that.submitPointsConfig(business_supplier_article);
                } else if (
                  business_supplier_article.filter((i) => i.Activity.length > 0)
                    .length > 0
                ) {
                  that.$message.success("开始插入活动商品");
                  that.submitActivityArticle(business_supplier_article);
                } else {
                  that.loading = false;
                  that.$message.success("提交成功");
                  window.history.go(-1);
                }
              },
            });
          } else {
            that.loading = false;
            // that.$message.error("每日库存单提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitPointsConfig(business_supplier_article) {
      //添加积分配置
      const that = this;
      let business_points_detail_config = [];
      business_supplier_article
        .filter(
          (i) =>
            i.Pionts.length > 0 &&
            !isNaN(i.Deduction_Limit) &&
            i.Deduction_Limit > 0
        )
        .forEach((item) => {
          business_points_detail_config.push({
            Points_Detail_Config_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Gift_Point: item.Pionts.some((i) => i == "Gift") ? "0" : "1",
            Sales_Point: item.Pionts.some((i) => i == "Sales") ? "0" : "1",
            Cash_Point: item.Pionts.some((i) => i == "Cash") ? "0" : "1",
            Activit_Point: item.Pionts.some((i) => i == "Activit") ? "0" : "1",
            Deduction_Type: item.Deduction_Type,
            Deduction_Limit: item.Deduction_Limit,
            Combination: "1",
          });
        });
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_points_detail_config } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            //插入活动商品
            if (
              business_supplier_article.filter((i) => i.Activity.length > 0)
                .length > 0
            ) {
              that.$message.success("开始插入活动商品");
              that.submitActivityArticle(business_supplier_article);
            } else {
              that.loading = false;
              that.$message.success("提交成功");
              window.history.go(-1);
            }
          } else {
            // that.$message.error("积分配置提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitActivityArticle(business_supplier_article) {
      //插入活动商品
      const that = this;
      let business_activity_article = [];
      business_supplier_article.forEach((item) => {
        item.Activity.filter(
          (i) =>
            i.Activity_SerialNumber &&
            !isNaN(i.Activity_Unit_Price) &&
            i.Activity_Unit_Price > 0
        ).forEach((ite) => {
          business_activity_article.push({
            Activity_Article_SerialNumber: "",
            Activity_SerialNumber: ite.Activity_SerialNumber,
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Article_SerialNumber: "",
            Article_Specifications_SerialNumber:
              item.Article_Specifications_SerialNumber,
            Activity_Unit_Price: ite.Activity_Unit_Price,
          });
        });
      });
      let base_operation_log = [
        generateLog(
          "插入活动商品",
          "平台端操作",
          "business_activity_article",
          JSON.stringify({ Add: { business_activity_article } })
        ),
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({
            Add: { business_activity_article, base_operation_log },
          }),
        },
        success: function (res) {
          if (res.Status === "success") {
            that.$message.success("提交成功");
            window.history.go(-1);
          } else {
            // that.$message.error("插入活动商品提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    add_article_specifications() {
      let Article_SerialNumber = sessionStorage.getItem("Article_SerialNumber");
      this.business_article_group[0].Children.business_article_group_detail.push(
        {
          id: createUniqueString(),
          Specification_Group_Detail_Name: "",
        }
      );
      this.business_article_specifications.push({
        Specifications_Name: "",
        Unit_Price: "", //吊牌价
        SKU_Quantity: "", //SKU数量
        Size: "",
        ADD: "ADD",
        Article_SerialNumber: Article_SerialNumber,
      });
      this.$forceUpdate();
      // this.form.Children.business_article_specifications.push({
      //     Article_Specifications_SerialNumber: '',//规格主键
      //     Article_SerialNumber: '',
      //     Specifications_Name: '',//规格名称
      //     Unit_Price: this.form.Unify_Unit_Price == '0' ? 0 : this.form.Unit_Price,//吊牌价
      //     SKU_Quantity: '',//SKU数量
      //     Size: '',
      //     Weight: '',//重量
      //     Weight_Unit: '',//单位
      //     JDCOM_Unit_Price: '',
      //     JDCOM_URL: '',
      //     Package_Quantity: '',//包装数量
      //     SKU_Package_Size: '',//包装尺寸
      //     Carton_Quantity: '',//大包装数量
      //     Children_Specifications_SerialNumber: '',
      //     Other: [{
      //         Supplier_SerialNumber: '',
      //         Sales_Unit_Price: '',
      //         Purchase_Unit_Price: '',
      //         Quantity: '',
      //         Pionts: [],
      //         Deduction_Type: '1',
      //         Deduction_Limit: '100',
      //         Activity: [{
      //             Activity_SerialNumber: '',
      //             Activity_Unit_Price: '',
      //         }]
      //     }]
      // })
    },
    remove_article_specifications() {
      //删除规格
      if (
        this.business_article_group[0].Children.business_article_group_detail
          .length > 1
      ) {
        this.business_article_group[0].Children.business_article_group_detail.pop();
        this.business_article_specifications.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
      // if (this.form.Children.business_article_specifications.length > 1) {
      //     this.form.Children.business_article_specifications.pop();
      // } else {
      //     this.$message({
      //         message: '不能在删除了',
      //         type: 'warning'
      //     })
      // }
    },
    changeSpecificationsName(index) {
      console.log(
        this.business_article_specifications[index].Specifications_Name
      );
      this.business_article_group[0].Children.business_article_group_detail[
        index
      ].Specification_Group_Detail_Name =
        this.business_article_specifications[index].Specifications_Name;
      this.$forceUpdate();
    },
    add_Other(obj) {
      obj.Other.push({
        Supplier_SerialNumber: "",
        Sales_Unit_Price: "",
        Purchase_Unit_Price: "",
        Quantity: "",
        Pionts: [],
        Deduction_Type: "1",
        Deduction_Limit: "100",
        Activity: [
          {
            Activity_SerialNumber: "",
            Activity_Unit_Price: "",
          },
        ],
      });
    },
    remove_Other(obj) {
      if (obj.Other.length > 0) {
        obj.Other.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
    },
    add_Activity(obj) {
      obj.Activity.push({
        Activity_SerialNumber: "",
        Activity_Unit_Price: "",
      });
    },
    remove_Activity(obj) {
      if (obj.Activity.length > 0) {
        obj.Activity.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
    },
    add_article_group_detail(item) {
      item.Children.business_article_group_detail.push({
        id: createUniqueString(),
        Specification_Group_Detail_Name: "",
      });
    },
    remove_article_group_detail(id, item) {
      item.Children.business_article_group_detail =
        item.Children.business_article_group_detail.filter((it, i) => i != id);
    },
    handleImgClick(formName) {
      //点击查看图片
      this.$refs[formName][0].showViewer = true;
    },
    RemoveImage(formName, index) {
      //删除图片
      this[formName].splice(index, 1);
    },
    sortable(that, container, element, jsonarray, className, callback) {
      //拖拽class配置
      var $ul = that.$el.querySelector(container);
      $ul.addEventListener("selectstart", function (e) {
        e.preventDefault();
      });
      this[className] = Sortable.create($ul, {
        handle: element,
        draggable: element,
        animation: 150,
        onUpdate: (event) => {
          let newIndex = event.newIndex,
            oldIndex = event.oldIndex;
          ($li = $ul.children[newIndex]), ($oldLi = $ul.children[oldIndex]);
          //先删除移动的节点, 再插入移动的节点到原有节点，还原了移动的操作
          $ul.removeChild($li);
          if (newIndex > oldIndex) {
            $ul.insertBefore($li, $oldLi);
          } else {
            $ul.insertBefore($li, $oldLi.nextSibling);
          }
          //通过改变vue遍历数组移动节点
          let item = jsonarray[oldIndex];
          jsonarray.splice(oldIndex, 1);
          jsonarray.splice(newIndex, 0, item);
          if (callback) callback(newIndex, oldIndex);
        },
      });
      this[className].option("disabled", true);
    },
  },
});
